<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>选择粉丝</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <#include '/frame/version.html'>
  <#include '/frame/manage/include_css.html'>
  <#include '/frame/manage/include_js.html'>
  <#include '/frame/taglib.html'>
</head>
<body style="background-color:#fff">
<div class="content" style="padding:5px;">
	<div class="cLine">
		<div class="pageNavigator left">
			<input type="button" value="打标签" class='btnGreen' id="btn_bindtags"/>
	    </div>
		<div class="pageNavigator right">
		 	昵称：<input class="px" name="nickName" placeholder="请输入昵称" maxlength="10"/>
			<input type="button" value="搜索" class='btnGreen' id="btn_search"/>
	    </div>
    </div>
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="ListProduct Shallow_border_color">
        <thead>
            <tr>
				<th></th>
				<th>粉丝头像</th>
				<th>昵称</th>
				<th>操作</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<script type="text/html" id="x-template">
{{# for(var i=0;i<d.length;i++){ }}
{{# var ele=d[i]; }}
<tr>
	<td><input type="checkbox" value="{{ele.id}}" name="fanId"/></td>
    <td><img src="{{ele.headimgurl}}" class="img_logo"/></td>
    <td>{{ele.nickname}}</td>
    <td class="norightborder">
        <a href="javascript:void(0)" onclick="chooseThis(this,{{ele.id}})">选中</a>
    </td>
</tr>
{{# } }}
</script>
<script type="text/javascript" src="${base}/js/layer/laytpl.js"></script>
<script type="text/javascript">
var template=$("#x-template").html();
function renderHtml(data){
	laytpl(template).render(data, function(html){
		$("table tbody").html(html);
	});
}
$("#btn_search").on('click',function(){
	var $this=$(this),$nickName=$this.prev(),nickName=$nickName.val();
	$.post(base+'/manage/tags/fans',{nickName:nickName},function(data){
		if(data){
			renderHtml(data);
		}
	});
});
var fanIds = new Array();
function chooseThis(that,id){
	fanIds.push(id);
	$(that).closest("tr").find(":checkbox").attr("checked","checked");
	stem.msg("已选择");
	$(that).remove();
}
var tagId=${tagId?default(0)};
$("#btn_bindtags").on('click',function(){
	var layIndex = stem.loading();
	if(fanIds.length==0){
		stem.warn("请先指定粉丝");
		stem.close(layIndex);
		return;
	}
	$.post(base+'/manage/tags/batch',{ids:fanIds.join(),tagId:tagId},function(data){
		if(data.state==200){
			stem.msg("打标签成功");
			parent.closeWindow();
		}else{
			stem.warn(data.msg);
		}
		stem.close(layIndex);
	});
});
</script>
</body>
</html>